<template>
	<view class="page has-fixed-footer">
		<page-header :showPlaceHolder="false" :showTitle="false"></page-header>
		<!-- 内容 -->
		<view class="content">
			<view class="title">
				{{store.getters.userType == '2' ? '供应商认证':'供应链认证'}}
			</view>
			<view class="prompt">
				{{store.getters.userType == '2' ? '完善以下资料，通过供应商认证':'完善以下资料，通过供应链认证'}}
			</view>
			<fui-steps :items="items" :fontWeight="550" :isMark="false" :current="current" :size="24" direction="row"
				:isWait="true" :lineThrough="true" color="#999999" nodeColor="#999999"></fui-steps>
			<fui-section descrColor="#666666" title="银行认证" isLine color="#333333" lineWidth="4px"></fui-section>

			<view class="fui-wrap">
				<fui-form ref="FormRef" :model="formData" :top="store.getters.statusBarHeight">
					<fui-form-item label="银行开户名" labelWeight="600" labelWidth="200" :left="0" labelSize="28"
						prop="bankAccountName">
						<fui-input :borderBottom="false" color="#333333" size="28" :padding="[0]" placeholder="请输入银行开户名"
							v-model="formData.bankAccountName"></fui-input>
					</fui-form-item>
					<fui-form-item label="开户行支行" labelWeight="600" labelWidth="200" :left="0" labelSize="28"
						prop="bankBranchName">
						<fui-input :borderBottom="false" color="#333333" size="28" :padding="[0]"
							placeholder="请输入开户行支行名称" v-model="formData.bankBranchName"></fui-input>
					</fui-form-item>
					<fui-form-item label="银行账号" labelWeight="600" :left="0" labelWidth="200" labelSize="28"
						prop="account">
						<fui-input :borderBottom="false" color="#333333" size="28" :padding="[0]" placeholder="请输入银行账号"
							v-model="formData.account"></fui-input>
					</fui-form-item>
				</fui-form>
			</view>
			<!-- 底部按钮 -->
			<fui-backdrop :show="isShow" closable @click="close">
				<Register :childProp="parentText" @end="end" @nextStep="nextStep"></Register>
			</fui-backdrop>
		</view>
		<view class="ui-fixed-footer ui-fixed-footer__white">
			<fui-button :disabled="false" height="78rpx" :margin="['612rpx','0','0','0 ']" disabledBackground="#DFDFDF"
				disabledColor="#666666" background="var(--fui-color-primary)" bold @click="submit">提交</fui-button>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		computed
	} from 'vue'
	import pageHeader from '@/components/header'
	import Register from '@/components/popup/register'
	import SystemApi from '@/api/system'
	import {
		useStore
	} from 'vuex';
	const store = useStore()
	const parentText = ref()
	let isShow = ref(false)
	const current = ref(3)
	const checkedval = ref(false)
	const FormRef = ref(null)
	// 营业执照表单
	const businessform = uni.getStorageSync('business')
	// 负责人表单
	const headform = uni.getStorageSync('Head')
	// 法人表单
	const legalpersonform = uni.getStorageSync('LegalPerson')
	const items = ref([{
		title: '公司认证',
		text: '1'
	}, {
		title: '法人认证',
		text: '2'
	}, {
		title: '负责人认证',
		text: '3'
	}, {
		title: '银行认证',
		text: '4'
	}])

	const rules = ref([{
		name: "bankAccountName",
		rule: ["required"],
		msg: ["请输入银行开户名"]
	}, {
		name: "bankBranchName",
		rule: ["required"],
		msg: ["请输入开户行支行"]
	}, {
		name: "account",
		rule: ["required"],
		msg: ["请输入银行账号"]
	}])
	const formData = ref({
		bankAccountName: '',
		bankBranchName: '',
		account: '',
		companyType: '0'
	})
	const close = (() => {
		isShow.value = false
	})
	const categoryList = businessform.Categoryval.split('|')
	const categoryIds = categoryList.map(item => {
		return item.split(',')[1]
	})
	const submitform = {
		loginPsw: headform.password,
		authenticationCycle: businessform.cycle,
		name: businessform.corporatename,
		creditCode: businessform.code,
		corporationName: legalpersonform.name,
		corporationPhone: legalpersonform.phone,
		corporationIdCard: legalpersonform.idcode,
		corporationFaceCheck: 'Y',
		address: businessform.corporateaddress,
		description: businessform.describe,
		idcFront: legalpersonform.idcFront,
		idcBack: legalpersonform.idcBack,
		businessLicense: businessform.businessurl,
		isSamePerson: legalpersonform.changeval == true ? 'Y' : 'N',
		adminName: headform.name,
		adminPhone: headform.phone,
		adminIdCard: headform.idcode,
		adminCardBack: headform.idcBack,
		adminCardFront: headform.idcFront,
		adminFaceCheck: 'Y',
		manageScope: businessform.Rangeval,
		categoryRange: categoryIds.join(','),
		bankInfo: formData.value,
    	companyType: '10'
	}
	const submitsupplierform = {
		isSamePerson: legalpersonform.changeval == true ? '1' : '0',
		adminName: headform.name,
		adminPhone: headform.phone,
		adminIdCard: headform.idcode,
		adminCardBack: headform.idcBack,
		adminCardFront: headform.idcFront,
		corporationName: legalpersonform.name,
		corporationPhone: legalpersonform.phone,
		corporationIdCard: legalpersonform.idcode,
		idcFront: legalpersonform.idcFront,
		idcBack: legalpersonform.idcBack,
		companyName: businessform.corporatename,
		creditCode: businessform.code,
		address: businessform.corporateaddress,
		description: businessform.describe,
		businessLicense: businessform.businessurl,
		credentials: "",
		tags: "",
		yunyfwId: "",
		yunyfw: businessform.Rangeval,
		yunyplId: "",
		yunypl: businessform.Categoryval,
		bankAccountName: '',
		bankBranchName: '',
		account: '',
		id:store.getters.companyId
	}
	const listApiUrl = computed(() => {
		let apiUrl = ''
		if (store.getters.userType == '') apiUrl = 'updateSupply' // 供应链提交
		if (store.getters.userType == '2') apiUrl = 'updateSupplier' // 供应商提交
		return apiUrl
	})
	const form = computed(() => {
		let formUrl = {}
		if (store.getters.userType == '') formUrl = submitform // 供应链提交表单
		if (store.getters.userType == '2') formUrl = submitsupplierform // 供应商提交表单
		return formUrl
	})
	//提交
	const submit = (async () => {
		const validRes = await FormRef.value.validator(formData.value, rules.value)
		if (store.getters.userType == '2') {
			submitsupplierform.account = formData.value.account
			submitsupplierform.bankAccountName = formData.value.bankAccountName
			submitsupplierform.bankBranchName = formData.value.bankBranchName
		}
		if (validRes.isPassed) {
			SystemApi[listApiUrl.value](form.value).then((res) => {
				if (res.code == 0) {
					parentText.value = 'submit'
					isShow.value = true
				}
			})
			// SystemApi.registerSupply(submitform).then((res) => {
			// 	if (res.code == 0) {
			// 		parentText.value = 'submit'
			// 		isShow.value = true
			// 	}
			// })
		}
	})
	const end = ((e) => {
		store.dispatch('LogOut')
	})
	const nextStep = (() => {
		store.dispatch('LogOut')
	})
	const back = (() => {
		uni.navigateBack({
			delta: 1
		})
	})
</script>

<style lang="scss" scoped>
	.page {
		position: relative;
		min-height: 100%;

		.content {
			margin: 36rpx;

			.title {
				font-size: 40rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				color: #333333;
			}

			.prompt {
				font-size: 24rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #999999;
				margin-top: 20rpx;
			}

			.fui-wrap {
				margin-top: 30rpx;
			}

			::v-deep.fui-steps__wrap {
				margin: 60rpx auto;
			}

			:deep(.fui-form__msg-wrap) {
				z-index: 11000;
			}

			::v-deep.fui-sections__wrap {
				padding: 0 !important;
			}

			::v-deep.fui-form__wrap-inner {
				padding: 0 !important;
			}

			::v-deep.uni-input-input {
				font-weight: bold;
			}

			::v-deep.textarea-box .fui-form__wrap-inner {
				display: initial !important;
			}
		}
	}
</style>